<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Member extends CI_Controller {

    function __construct() {
        parent::__construct();

        /* Standard Libraries of codeigniter are required */
        $this->load->database();
        $this->load->helper('url');
        
        /* ------------------ */

        $this->load->library('ExCRUD');
    }   
    
    function testimoni(){
        $crud = new ExCRUD();        
        $crud->standartCheck();  
        
        // 1. set table & relation
        $crud->set_table('testimoni'); 
        $crud->set_primary_key("id_testimoni");
        $crud->order_by('id_testimoni','desc');
        $crud->field_type('is_publish', 'dropdown', array('1' => 'TAMPILKAN', '-1' => 'SEMBUNYIKAN'));
        $crud->set_field_readonly($crud, array("id_member","alias_member","date_created"));        
        
        // render it dude
        $output = $crud->render();
        $this->load->view('template/view_admin',$output);
    }
    
    function data(){
        $crud = new ExCRUD();        
        $crud->standartCheck();  
        
        // 1. set table & relation
        $crud->set_table('v_member'); 
        $crud->set_primary_key("id_member");
        $crud->order_by('alias_member','asc');
        
        // 2. set table display        
        $crud->set_delete(false);         
        $crud->set_add(false);  
        $crud->set_edit(false);        
        
        $crud->add_action('Geneologi Member', base_url('static/images/tree.png'), 'network/index');
        $crud->add_action('Board Member', base_url('static/images/board.png'), 'network/board');
        $crud->add_action('Edit Member', base_url('static/images/edit.png'), 'member/data_edit/edit');        
                
        // render it dude
        $output = $crud->render();
        $this->load->view('template/view_admin',$output);
    }    
    
    function data_edit(){        
        $crud = new ExCRUD();        
        if ($crud->getState() != "edit"){
           header("location:".base_url("index.php/member/data"));
        }
        $crud->standartCheck();  
        
        // 1. set table & relation
        $crud->set_table('member');       
        $crud->set_relation('upline','member','{alias_member} ({nickname})');
        $crud->set_primary_key("id_member");
        $crud->order_by('alias_member','asc');
        
        // 2. set table display        
        $crud->set_delete(false);         
        $crud->set_add(false);  
        $crud->add_action('Geneologi Member', base_url('static/images/tree.png'), 'network/index');
        $crud->add_action('Board Member', base_url('static/images/board.png'), 'network/board');
                
        $list_column_views = array('alias_member', 'nickname', 'level', 'poin_balance', 'upline', 'email', 'no_hp');
        $crud->columns($list_column_views);        
        $crud->display_as("alias_member","ID Member");
        $crud->display_as("upline","Sponsor");
        
        // 4. aturan kolom                
        $list_column_hidden = array('foto_member', 'date_reset','alias_upline');
        $list_column_ro = array('upline', 'poin_balance', 'date_active', 'alias_member', 'level');        
        $required_fields = array('no_hp','nickname');        
        $crud->set_field_readonly($crud, $list_column_ro);
        $crud->set_field_hidden($crud, $list_column_hidden);        
        $crud->required_fields($required_fields);
                
        // render it dude
        $output = $crud->render();
        $this->load->view('template/view_admin',$output);
    }    
    
    function aktifasi(){
        $list_column_views = array('alias_member', 'nama_registran', 'no_hp_registran', 'email_registran', 'date_submit', 'date_activated');        
        $list_column_hidden = array('id_member');        
        $list_column_ro = array('date_activated', 'date_submit', 'id_request_pin', 'alias_member');
        
        $crud = new ExCRUD();
        $crud->standartCheck();        
        $crud->set_table('request_daftar');        
        $crud->set_primary_key("id_request");
        $crud->where("date_activated <>", "0000-00-00 00-00-00");
        $crud->order_by('id_request','asc');
        
        $crud->columns($list_column_views);        
                
        $crud->set_field_hidden($crud, $list_column_hidden);
        $crud->set_field_readonly($crud, $list_column_ro);
        
        $crud->set_delete(false);
        $crud->seM70003t_add(false);
        
        
        $output = $crud->render();
        $this->load->view('template/view_admin',$output);
    }  
    
    function mutasi(){
        $list_column_views = array('alias_member', 'id_transaksi', 'last_poin', 'penambahan', 'pengurangan', 'current_poin', 'tanggal_mutasi');        
        $list_column_hidden = array('id_mutasi','id_member');                
        
        $crud = new ExCRUD();
        $crud->standartCheck();        
        $crud->set_table('mutasi_poin');        
        $crud->set_primary_key("id_mutasi");
        $crud->order_by('id_mutasi','asc');
        
        $crud->columns($list_column_views);        
                
        $crud->set_field_hidden($crud, $list_column_hidden);        
        
        $crud->set_delete(false);
        $crud->set_add(false);
        $crud->set_edit(false);
        
        
        $output = $crud->render();
        $this->load->view('template/view_admin',$output);
    }
    
    function komplain(){
        $crud = new ExCRUD();        
        $crud->standartCheck();  
        
        // 1. set table & relation
        $crud->set_table('komplain'); 
        $crud->set_primary_key("id_komplain");
        $crud->order_by('date_created','desc');
        $crud->set_field_readonly($crud, array("id_member","alias_member","isi","date_created","jumlah_respon", 'status'));        
        $crud->field_type('status', 'dropdown', array(0 => "Baru Masuk", 1 => "Terima", -1 => "Acuhkan"));
        
        $crud->set_add(false);
        $crud->callback_after_update(function($post_data, $primary_key){
            $ci = &get_instance();
            $ci->load->model("member_model");
            
            $ci->member_model->increment_complaint_response($primary_key);
        });
        
        // render it dude
        $output = $crud->render();
        $this->load->view('template/view_admin',$output);
    }
}



/* End of file main.php */
/* Location: ./application/controllers/main.php */